Skip to content

fix(worker): propagate batch token logprobs through CompletionOutlet - #898

Merged
Andrewxu313 merged 1 commit into
mainfrom
tairan/fix-deferred-logprobs
Dec 4, 2026
Merged

Andrewxu313 merged 1 commit into
mainfrom
tairan/fix-deferred-logprobs

Conversation

@Andrewxu313

Copy link
Copy Markdown
Contributor

Description

Wire _batch_logprobs through CompletionOutlet.gather_completed_tokens and CompletionOutlet.report_completion, matching BatchGenWorker._gather_completed_tokens / _report_completion.

Motivation

CompletionOutlet was extracted after the batch-logprobs path and omitted cross-rank logprob gathering, merging on rank 0, token_logprobs emission in the completion payload, and per-rank cleanup. Consequently, any batch API request with logprobs that completed during decode (routed via BoundaryExecutor -> CompletionOutlet) failed with invalid_worker_logprobs: expected logprobs for all N generated tokens.

This fix also skips redundant history.stage(...) calls in _select_tokens for already-completed rows waiting for the next page boundary and guards self-merge when records is history.records.

Type of Change

  • fix — narrow bug fix (+ a regression test)

File changes

File Δ Note
batchgen/worker/completion.py mod Add batch_logprobs field to CompletionOutlet; gather, merge on rank 0, emit token_logprobs, and pop per-rank history on completion
batchgen/batchgen_worker.py mod Pass _batch_logprobs to CompletionOutlet, guard self-merge, and skip staging for already-completed rows in _select_tokens
tests/unit/server/test_batch_logprobs.py mod Add unit tests for CompletionOutlet cross-rank gather/merge/emit and non-zero rank cleanup

Checklist

  • I have read the CONTRIBUTING guide and the PR Merge Policy Contract.
  • I have updated the tests (if applicable).
  • I have updated the documentation (if applicable).
  • If README.md changed, I ran python3 scripts/check_readme_update.py --base-ref origin/main and preserved all News history.

CompletionOutlet.gather_completed_tokens and report_completion were
introduced after the batch-logprobs path and omitted _batch_logprobs
gathering, cross-rank merging, response-queue emission, and per-rank
cleanup. Any batch request with logprobs that completed during decode
(max_completion_tokens >= 2) went through BoundaryExecutor ->
CompletionOutlet and failed with invalid_worker_logprobs.

Pass batch_logprobs into CompletionOutlet, mirror the gather/merge/pop
protocol identically to BatchGenWorker, guard self-merge and already-
completed decode rows in _select_tokens, and add unit tests covering
cross-rank merge and non-zero rank cleanup.
@Andrewxu313
Andrewxu313 merged commit 09be8d3 into main Dec 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant